package jam.network.message;

import jam.network.NetworkController;
import jam.model.*;
import jam.UserInterface.UI.UIController;

import java.util.Scanner;
import java.lang.String;

public class ResponseUserInfo extends ServerResponse {

	public static void process(String msg, ClientModel cm) {


		Scanner s = new Scanner( msg );
		s.useDelimiter(":");

		//skip keyword and transID
		s.next();
		int id = s.nextInt();
		
		//clean up hashmap
		NetworkController.sent.remove(id);
	
		String result = s.next();

		if ( result.equalsIgnoreCase("TRUE") ) {
			String fname = s.next();
			System.out.println(fname);
			String sname = s.next();
			System.out.println(sname);
			String email = s.next();
			System.out.println(email);
			String avatar = s.next();
			System.out.println(avatar);
			String status = s.next();
			if (status.equals("TRUE"))
				status = "Available";
			else
				status = "Offline";
			System.out.println(status);

			User u = new User(fname, sname, email, avatar, /*"test display",*/ status);
			System.out.println("User object created");
			
			if (cm.getUser() == null) {
				cm.setUser( u );
			}
			else {
				cm.addtocl( u );
				//UIcontroller.updateContacts(u);
			}
		}
		
		else 
			System.out.println("Failed to get user info" );
		
	}

}